/**
 */
package Alloy.impl;

import Alloy.AlloyPackage;
import Alloy.ModeRuleset;
import Alloy.Universal;

import Alloy.Variable;
import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Mode Ruleset</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link Alloy.impl.ModeRulesetImpl#getBearerVariable <em>Bearer Variable</em>}</li>
 *   <li>{@link Alloy.impl.ModeRulesetImpl#getBearer <em>Bearer</em>}</li>
 *   <li>{@link Alloy.impl.ModeRulesetImpl#getMode <em>Mode</em>}</li>
 *   <li>{@link Alloy.impl.ModeRulesetImpl#getCharacterization <em>Characterization</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ModeRulesetImpl extends RulesetImpl implements ModeRuleset {
	/**
	 * The cached value of the '{@link #getBearerVariable() <em>Bearer Variable</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBearerVariable()
	 * @generated
	 * @ordered
	 */
	protected Variable bearerVariable;

	/**
	 * The cached value of the '{@link #getBearer() <em>Bearer</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBearer()
	 * @generated
	 * @ordered
	 */
	protected Universal bearer;

	/**
	 * The cached value of the '{@link #getMode() <em>Mode</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMode()
	 * @generated
	 * @ordered
	 */
	protected Universal mode;

	/**
	 * The cached value of the '{@link #getCharacterization() <em>Characterization</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCharacterization()
	 * @generated
	 * @ordered
	 */
	protected Universal characterization;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ModeRulesetImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return AlloyPackage.Literals.MODE_RULESET;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Variable getBearerVariable() {
		return bearerVariable;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetBearerVariable(Variable newBearerVariable, NotificationChain msgs) {
		Variable oldBearerVariable = bearerVariable;
		bearerVariable = newBearerVariable;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, AlloyPackage.MODE_RULESET__BEARER_VARIABLE, oldBearerVariable, newBearerVariable);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setBearerVariable(Variable newBearerVariable) {
		if (newBearerVariable != bearerVariable) {
			NotificationChain msgs = null;
			if (bearerVariable != null)
				msgs = ((InternalEObject)bearerVariable).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - AlloyPackage.MODE_RULESET__BEARER_VARIABLE, null, msgs);
			if (newBearerVariable != null)
				msgs = ((InternalEObject)newBearerVariable).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - AlloyPackage.MODE_RULESET__BEARER_VARIABLE, null, msgs);
			msgs = basicSetBearerVariable(newBearerVariable, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, AlloyPackage.MODE_RULESET__BEARER_VARIABLE, newBearerVariable, newBearerVariable));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Universal getBearer() {
		if (bearer != null && bearer.eIsProxy()) {
			InternalEObject oldBearer = (InternalEObject)bearer;
			bearer = (Universal)eResolveProxy(oldBearer);
			if (bearer != oldBearer) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, AlloyPackage.MODE_RULESET__BEARER, oldBearer, bearer));
			}
		}
		return bearer;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Universal basicGetBearer() {
		return bearer;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setBearer(Universal newBearer) {
		Universal oldBearer = bearer;
		bearer = newBearer;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, AlloyPackage.MODE_RULESET__BEARER, oldBearer, bearer));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Universal getMode() {
		if (mode != null && mode.eIsProxy()) {
			InternalEObject oldMode = (InternalEObject)mode;
			mode = (Universal)eResolveProxy(oldMode);
			if (mode != oldMode) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, AlloyPackage.MODE_RULESET__MODE, oldMode, mode));
			}
		}
		return mode;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Universal basicGetMode() {
		return mode;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMode(Universal newMode) {
		Universal oldMode = mode;
		mode = newMode;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, AlloyPackage.MODE_RULESET__MODE, oldMode, mode));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Universal getCharacterization() {
		if (characterization != null && characterization.eIsProxy()) {
			InternalEObject oldCharacterization = (InternalEObject)characterization;
			characterization = (Universal)eResolveProxy(oldCharacterization);
			if (characterization != oldCharacterization) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, AlloyPackage.MODE_RULESET__CHARACTERIZATION, oldCharacterization, characterization));
			}
		}
		return characterization;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Universal basicGetCharacterization() {
		return characterization;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCharacterization(Universal newCharacterization) {
		Universal oldCharacterization = characterization;
		characterization = newCharacterization;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, AlloyPackage.MODE_RULESET__CHARACTERIZATION, oldCharacterization, characterization));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case AlloyPackage.MODE_RULESET__BEARER_VARIABLE:
				return basicSetBearerVariable(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case AlloyPackage.MODE_RULESET__BEARER_VARIABLE:
				return getBearerVariable();
			case AlloyPackage.MODE_RULESET__BEARER:
				if (resolve) return getBearer();
				return basicGetBearer();
			case AlloyPackage.MODE_RULESET__MODE:
				if (resolve) return getMode();
				return basicGetMode();
			case AlloyPackage.MODE_RULESET__CHARACTERIZATION:
				if (resolve) return getCharacterization();
				return basicGetCharacterization();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case AlloyPackage.MODE_RULESET__BEARER_VARIABLE:
				setBearerVariable((Variable)newValue);
				return;
			case AlloyPackage.MODE_RULESET__BEARER:
				setBearer((Universal)newValue);
				return;
			case AlloyPackage.MODE_RULESET__MODE:
				setMode((Universal)newValue);
				return;
			case AlloyPackage.MODE_RULESET__CHARACTERIZATION:
				setCharacterization((Universal)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case AlloyPackage.MODE_RULESET__BEARER_VARIABLE:
				setBearerVariable((Variable)null);
				return;
			case AlloyPackage.MODE_RULESET__BEARER:
				setBearer((Universal)null);
				return;
			case AlloyPackage.MODE_RULESET__MODE:
				setMode((Universal)null);
				return;
			case AlloyPackage.MODE_RULESET__CHARACTERIZATION:
				setCharacterization((Universal)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case AlloyPackage.MODE_RULESET__BEARER_VARIABLE:
				return bearerVariable != null;
			case AlloyPackage.MODE_RULESET__BEARER:
				return bearer != null;
			case AlloyPackage.MODE_RULESET__MODE:
				return mode != null;
			case AlloyPackage.MODE_RULESET__CHARACTERIZATION:
				return characterization != null;
		}
		return super.eIsSet(featureID);
	}

} //ModeRulesetImpl
